package com.zhou.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.zhou.admin.entity.UmsResource;
import com.zhou.admin.entity.UmsRole;
import com.zhou.admin.service.UmsResourceService;
import com.zhou.common.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 后台资源管理Service实现类
 *
 */
@Service
public class UmsResourceServiceImpl implements UmsResourceService {
//    @Autowired
//    private UmsResourceMapper resourceMapper;
//    @Autowired
//    private UmsRoleMapper roleMapper;
//    @Autowired
//    private UmsRoleResourceRelationMapper roleResourceRelationMapper;
//    @Autowired
//    private RedisService redisService;
//    @Value("${spring.application.name}")
//    private String applicationName;
//    @Override
//    public Map<String,List<String>> initResourceRolesMap() {
//        Map<String,List<String>> resourceRoleMap = new TreeMap<>();
//        List<UmsResource> resourceList = resourceMapper.selectByExample(new UmsResourceExample());
//        List<UmsRole> roleList = roleMapper.selectByExample(new UmsRoleExample());
//        List<UmsRoleResourceRelation> relationList = roleResourceRelationMapper.selectByExample(new UmsRoleResourceRelationExample());
//        for (UmsResource resource : resourceList) {
//            Set<Long> roleIds = relationList.stream().filter(item -> item.getResourceId().equals(resource.getId())).map(UmsRoleResourceRelation::getRoleId).collect(Collectors.toSet());
//            List<String> roleNames = roleList.stream().filter(item -> roleIds.contains(item.getId())).map(item -> item.getId() + "_" + item.getName()).collect(Collectors.toList());
//            resourceRoleMap.put("/"+applicationName+resource.getUrl(),roleNames);
//        }
//        redisService.del(AuthConstant.RESOURCE_ROLES_MAP_KEY);
//        redisService.hSetAll(AuthConstant.RESOURCE_ROLES_MAP_KEY, resourceRoleMap);
//        return resourceRoleMap;
//
//    }
}
